﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using HMS_Hospital_Team2._6.DA;
using HMS_Hospital_Team2._6.BL;
using HMS_Hospital_Team2._6.DO;
using HMS_Hospital_Team2._6.GUI;
using System.Windows.Forms;

namespace HMS_Hospital_Team2._6.GUI
{
    public partial class frmSelectPostion : Form
    {
        //HMSHospitalEntities context = new HMSHospitalEntities();
        NhanVienBL Nhanvien = new NhanVienBL();
        PhongBanBL PhongBan = new PhongBanBL();
        public string sMaPB = "";
        string stendn = "";
        string smk = "";
        public string sMaban = "";
        public int sVaitro = 0;
        public bool blclick = false;

        public frmSelectPostion()
        {
            InitializeComponent();
        }

        public frmSelectPostion(string s1, string s2)
        {
            stendn = s1;
            smk = s2;
            InitializeComponent();
        }
        //xử lý khi nhấn nút hoàn tất
        private void btnHoanTatViTri_Click(object sender, EventArgs e)
        {
            if (cmbDonVi_ChonVT.SelectedItem != null && cmbChonBan_ChonVT.SelectedItem != null && cmbChonVaiTro_ChonVT.SelectedItem != null)
            {
                HMSHospitalEntities context = new HMSHospitalEntities();
                List<phanquyen> thongtintk = BL.NhanVienBL.Loadthongtindangnhap_BL(stendn, smk);
                var maban = from mb in context.ThongTinBanThus
                            select mb;
                int icount = 1;
                foreach(var row in maban)
                {
                    icount++;
                }
                sMaPB = cmbDonVi_ChonVT.SelectedValue.ToString();
                sMaban = cmbChonBan_ChonVT.SelectedValue.ToString();
                sVaitro = cmbChonVaiTro_ChonVT.SelectedIndex;
                string sMaNV = thongtintk[0].MaNhanVien;
                string sMattBanthu = sMaban + "-" + sMaNV +"-"+ icount;

                string sVitri = cmbChonVaiTro_ChonVT.SelectedItem.ToString();
                DateTime daThoigiansd = DateTime.Now;
                BL.ThongTinBanThuBL.LuuThongTinBanThu_BL(sMaban, sMaNV, sMattBanthu, sVitri, daThoigiansd);
                this.Close();

                blclick = true;
            }
            else
            {
                if (cmbDonVi_ChonVT.SelectedItem == null)
                {
                    MessageBox.Show("Vui lòng chọn đơn vị thu ngân", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    if (cmbChonBan_ChonVT.SelectedItem == null)
                    {

                        MessageBox.Show("Vui lòng chọn bàn thu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        if (cmbChonVaiTro_ChonVT.SelectedItem == null)
                            MessageBox.Show("Vui lòng chọn vai trò", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }

        }


        private void frmSelectPostion_Load(object sender, EventArgs e)
        {

            //Load data lên combobox Chọn Đơn vị
            cmbDonVi_ChonVT.DataSource = PhongBan.LoadPhongBan_BL();
            cmbDonVi_ChonVT.DisplayMember = "TenPhongBan";
            cmbDonVi_ChonVT.ValueMember = "MaPhongBan";
            cmbDonVi_ChonVT.SelectedItem = null;
        }
        //xu li khi chon don vi thi se load len combobox nhg ban thuoc don vi do
        private void cmbDonVi_ChonVT_SelectionChangeCommitted(object sender, EventArgs e)
        {
            string sMaPB = cmbDonVi_ChonVT.SelectedValue.ToString();
            cmbChonBan_ChonVT.Enabled = true;
            cmbChonBan_ChonVT.DataSource = PhongBan.Loadthongtinbanthu_BL(sMaPB);
            cmbChonBan_ChonVT.DisplayMember = "TenBan";
            cmbChonBan_ChonVT.ValueMember = "MaBan";
            cmbChonBan_ChonVT.SelectedItem = null;
        }

        private void cmbChonBan_ChonVT_SelectionChangeCommitted(object sender, EventArgs e)
        {
            cmbChonVaiTro_ChonVT.Enabled = true;
            cmbChonVaiTro_ChonVT.SelectedItem = null;
        }
    }

}
